#include <stdio.h>
#include <stdlib.h> /*needed for exit()*/

int main()
{
    int ch, n;
    long int offset, last;
    FILE *inFile; /*FILE declaration*/

    inFile = fopen("text.dat", "r");
    if (inFile == NULL)
    {
        printf("\nFailed to open the text.dat file.\n");
        exit(1);
    }
    fseek(inFile, 0L, SEEK_END); /*move to the end of the file*/
    last = ftell(inFile);        /*save the offset of the last character*/
    for (offset = 0; offset <= last; offset++)
    {
        fseek(inFile, -offset, SEEK_END);

        ch = getc(inFile);
        switch (ch)
        {
        case '\n':
            printf("LF : ");
            break;
        case EOF:
            printf("EOF: ");
            break;
        default:
            printf("%c : ", ch);
            break;
        }
    }
    fclose(inFile);

    return 0;
}